package backend.service.admin;

import backend.model.admin.Sfi;
import backend.service.base.DBModelServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SfiServiceImpl extends DBModelServiceImpl<Sfi> implements SfiService {

    @Override
    public Class<Sfi> getEntityClass() {
        return Sfi.class;
    }

    @Override
    public List<Sfi> findAllSfis() {
        return dbModelDao.findByNamedQuery("findAllSfis");
    }

    @Override
    public List<Sfi> findAllActiveSfis() {
        return dbModelDao.findByNamedQuery("findAllActiveSfis");
    }

    public Sfi findSfiByName(String name){
        List<Sfi> sfisByName = dbModelDao.findByNamedQueryAndParams("findSfiByName", new String[]{"name"}, new Object[]{name});
        assert sfisByName.size() <= 1;
        if (sfisByName.size() == 1) {
            return sfisByName.get(0);
        }
        return null;
    }
}